Skip to content

ref(autofix): Split explorer response into sections#110527

Merged
Zylphrex merged 5 commits intomasterfrom
txiao/ref/split-explorer-response-into-sections
Mar 12, 2026
Merged

ref(autofix): Split explorer response into sections#110527
Zylphrex merged 5 commits intomasterfrom
txiao/ref/split-explorer-response-into-sections

Conversation

@Zylphrex
Copy link
Member

@Zylphrex Zylphrex commented Mar 12, 2026

Directly extracting the artifacts makes it hard to handle the loading states. This refactors it so the response is split into sections according to the step, then we find the last matching artifact from the step.

Directly extracting the artifacts makes it hard to handle the loading states.
This refactors it so the response is split into sections according to the step,
then we find the last matching artifact from the step.
@Zylphrex Zylphrex requested a review from a team as a code owner March 12, 2026 15:41
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 12, 2026
Comment on lines +65 to +67
{sections.map(section => {
if (isRootCauseSection(section)) {
return <RootCauseCard key={section.step} section={section} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Re-running an autofix step creates components with duplicate React key props because section.step is used as the key, leading to potential rendering issues.
Severity: MEDIUM

Suggested Fix

To ensure stable and unique keys for React's reconciliation algorithm, generate a unique identifier for each section when it is created. This unique ID should be used as the key prop instead of the non-unique section.step string.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: static/app/components/events/autofix/v3/content.tsx#L65-L67

Potential issue: When a user re-runs an autofix step, such as 'root_cause', the
`getOrderedAutofixSections` function creates a new section object. Both the old and new
sections for that step will have the same `step` name (e.g., 'root_cause'). In
`content.tsx`, the code maps over these sections and uses `section.step` as the React
`key` prop. This results in multiple components in the list having the same key, which
can lead to unpredictable UI behavior, incorrect component state, and rendering issues
in React.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectation is only 1 of each step exists

}

if (isArrayOf(artifact, isRepoPRState) && artifact.length) {
return <PullRequestsCard key="pull-requests" artifact={artifact} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate React keys when sections share step names

Medium Severity

Sections are rendered using key={section.step}, but getOrderedAutofixSections can produce multiple sections with the same step value (e.g., when a step is retried via the "No" button calling startStep with the same step name, the backend may append new blocks with a repeated metadata.step). Duplicate React keys cause incorrect DOM reuse and rendering glitches. Consider using the section's index or a unique identifier as the key instead.

Additional Locations (1)
Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectation is only 1 of each step exists

Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

}

section.messages.push(message);
section.artifacts.push(...(block.artifacts ?? []));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patches collected before prior section is finalized

Low Severity

In the loop inside getOrderedAutofixSections, each block's merged_file_patches are added to mergedByFile before finalizeSection() is called for the previous section. If a block that starts a new section also carries merged_file_patches, those patches leak into the previous code_changes section's artifact snapshot. The patch collection (lines 346–351) needs to happen after the finalization check (lines 356–365) to ensure the outgoing section receives only patches from its own blocks.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional

export function getOrderedAutofixArtifacts(
runState: ExplorerAutofixState | null
): AutofixArtifact[] {
export function getOrderedAutofixSections(runState: ExplorerAutofixState | null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind adding some comments on the operations being done in this function? I found the imperative style of updating section and pushing to sections a little confusing to read, though makes sense now

OrderedArtifact | OrderedExplorerFilePatch
>();
const mergedByFile = new Map<string, ExplorerFilePatch>();
function finalizeSection() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a comment on what this fx does

@Zylphrex Zylphrex merged commit cadffd9 into master Mar 12, 2026
63 checks passed
@Zylphrex Zylphrex deleted the txiao/ref/split-explorer-response-into-sections branch March 12, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants